;
(function (call) {
    var main = {
        userInfo: null,
        init: function () {
            this.initView();
            this.bindEvt();
        },
        initView: function () {
            var that = this;
            var userInfo = $("#userInfo").data('info');
            this.userInfo = userInfo;
            var time = new Date().format('yyyy-MM-dd hh:mm');
            $("#hour").val(new Date(time).format('hh'));
            that.initForecast();
        },
        initForecast:function(){
            var that = this;
            $.ajax({
                url: api.internal.sxtqhszdcp.querySxForecasterMsg,
                type: "post",
                dataType: "json",
                success: function (res) {
                    if (res.isSuccess) {
                        var data = res.data || [];
                        var html = "";
                        for(var i = 0;i<data.length;i++){
                            html+="<option lid="+data[i].userId+">"+data[i].userNm+"</option>";
                        }
                        $("#forecastSele").empty().append(html);
                    } else {
                        alert("查询预报员失败")
                    }
                },
            })
        },
        publishData: function () {
            var that = this;
            var productInfo = $(".task-menu-list li.active").data('product');
            var data = {
                "fbhour":$("#hour").val(),
                "unit":$("#sxname").val(),
                "sxname":$("#forecastSele").find("option:selected").text(),
                "wp3day":$("#wp3day").val(),
                "tj24h":$("#tj24h").val(),
                "tj48h":$("#tj48h").val(),
                "tj72h":$("#tj72h").val(),
                "bf24h":$("#bf24h").val(),
                "bf48h":$("#bf48h").val(),
                "bf72h":$("#bf72h").val(),
                "hh24h":$("#hh24h").val(),
                "hh48h":$("#hh48h").val(),
                "hh72h":$("#hh72h").val(),
                "hscontent":$("#hscontent").val()
            }
            data = JSON.stringify(data);
            loading.add('.cafe-container');
            $.ajax({
                url: api.internal.sxtqhszdcp.pushforeWord,
                type: "post",
                data: {
                    "taskId":"TJ_SXTQHSZDCP",
                    "product_id": "TJ_SXTQHSZDCP",
                    "forecasterId": $("#forecastSele").find("option:selected").attr("lid"),
                    "jsonStr": data
                },
                dataType: "json",
                success: function (res) {
                    loading.remove();
                    if (res.isSuccess) {
                        alert("发布成功");
                        CafeJS.menuFunc.setTask();
                       that.productPreview(res.data);
                    } else {
                        alert("发布失败")
                    }
                },
            })
        },
        productPreview: function (filePath) {
            $("#contentFrame").attr("src", "http://10.226.120.202:80//ioffice/officeView.do?path=" + encodeURI(encodeURI(filePath)));
        },
        bindEvt: function () {
            var that = this;
            //点击发布
            $("#publishBtn").click(function () {
                that.publishData();
            });
            //点击重做
            $("#returnBtn").click(function () {
                $("#contentFrame").attr("src", "");
                $("#wp3day").val("");
                $("#tj24h").val("");
                $("#tj48h").val("");
                $("#tj72h").val("");
                $("#bf24h").val("");
                $("#bf48h").val("");
                $("#bf72h").val("");
                $("#hh24h").val("");
                $("#hh48h").val("");
                $("#hh72h").val("");
                $("#hscontent").val("");
            })

        }
    };
    if (typeof call === 'function') {
        call(main);
    }
})(function (main) {
    main.init();
})